package com.ai.api.controller;

import com.ai.bo.JobBo;
import com.ai.grace.result.GraceJSONResult;
import com.ai.service.JobService;
import com.ai.vo.JobNameVO;
import com.ai.vo.JobVO;
import com.github.pagehelper.PageInfo;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import wst.ai.pojo.job.Job;

import java.util.List;

@RestController
@RequestMapping("job")
public class JobController {
    @Autowired
    private JobService jobService;
    @GetMapping("list")
    public GraceJSONResult getJobList(@RequestParam(defaultValue = "1",name = "page") Integer page, @RequestParam(defaultValue = "10",name = "pageSize") Integer pageSize){
        PageInfo<JobVO> jobList = jobService.getJobList(page, pageSize);
        return GraceJSONResult.ok(jobList);
    }

    /**
     * 新增职位
     * @param jobBo
     * @return
     */
    @PostMapping("createOrUpdate")
    public GraceJSONResult createOrUpdate(@Valid @RequestBody JobBo jobBo){
        jobService.newJob(jobBo);
        return GraceJSONResult.ok();
    }
    @GetMapping("detail")
    public GraceJSONResult detail(@RequestParam String jobId){
        Job job = jobService.getJobById(jobId);
        return GraceJSONResult.ok(job);
    }
    @PostMapping("delete")
    public GraceJSONResult delete(@RequestParam String jobId){
        jobService.deleteJob(jobId);
        return GraceJSONResult.ok();
    }
    @GetMapping("nameList")
    public GraceJSONResult nameList(){
        List<JobNameVO> nameList = jobService.getNameList();
        return GraceJSONResult.ok(nameList);
    }
}
